1. Field of the Invention
The invention relates to flash devices, and more particularly to data recovery of flash devices.
2. Description of the Related Art
A flash device, such as a memory card, is a device comprising a flash memory for data storage. A flash memory is a non-volatile memory that can be electrically erased and reprogrammed. A flash device stores data for a host such as a personal computer. When the host wants to store data to the flash device, the host sends data along with a logical address of the data to the flash device, wherein the logical address indicates the location at which the data is to be stored. The flash memory, however, stores data according to physical addresses. The flash device therefore must first convert the logical address sent by the host into a physical address, and then directs the flash memory to store the data in the memory space with the physical address. The flash device therefore comprises a microprocessor capable of converting logical addresses of the host into physical addresses of the flash memory.
To convert logical addresses into physical addresses, the flash device therefore has to record a mapping relationship between logical addresses and physical addresses. The mapping relationship between logical addresses and physical addresses is referred to as flash-translation-layer (FTL) data. The FTL data is often stored in the flash memory of the flash device. When the flash device is enabled, the microprocessor loads the FTL data from the flash memory to a dynamic random access memory (DRAM) of the flash device, and then the microprocessor converts logical addresses into physical addresses according to the FTL data stored in the DRAM.
Whenever a time period has passed, the microprocessor of the flash device must update the FTL data stored in the flash memory according to the latest FTL data stored in the DRAM, thus the FTL data stored in the flash memory is kept to be identical with the latest FTL data stored in the DRAM. However, when power of the flash device is suddenly shut down, the FTL data stored in the flash memory has no time to be updated, and the latest FTL data stored in the DRAM is lost due to the sudden shut down of power. After the power of the flash device is regained, the microprocessor of the flash device must first recover the latest FTL data. Otherwise, because the version of FTL data stored in the flash memory is not the latest data version, the microprocessor would convert logical addresses into physical addresses according to wrong information of the FTL data. For example, when the host requests the flash device to read data, the flash device may read an old physical address of the flash memory to obtain wrong data. When the host requests the flash device to write data thereto, the flash device may mistake a used data block as an empty data block and overwrite data in the used data block. Thus, a method for recovering the latest FTL data for a flash device is required.